<?php
namespace app\modules\admin\controllers;

/**
 * 管理员控制器
 * User: JSparrow
 * DateTime: 2016/11/22 15:31
 * Created by PhpStorm.
 */

use app\models\Admin;
use app\modules\admin\models\form\AdminForm;
use yii\web\Controller;

class AdminController extends Controller
{
    /**
     * 说明: 管理员列表
     * @return string
     */
    public function actionIndex() {
        $models = Admin::find()->all();

        return $this->render('index', ['models'=>$models]);
    }

    /**
     * 说明: 新建管理员
     * @return string|\yii\web\Response
     */
    public function actionCreate() {
        $model = new AdminForm();
        $model->setScenario(AdminForm::SCENARIO_CREATE);
        if($model->load(\Yii::$app->request->post()) && $model->create()) {
            return $this->redirect(['admin/index']);
        }
        return $this->render('create', ['model'=>$model]);
    }

    /**
     * 说明: 更新管理员信息
     * @param $id int 管理id
     * @return string
     */
    public function actionUpdate($id) {
        $model = new AdminForm();
        $model->setScenario(AdminForm::SCENARIO_UPDATE);
        if($model->load(\Yii::$app->request->post()) && $model->update()) {
            return $this->redirect(['admin/index']);
        }
        return $this->render('update', ['model'=>$model]);
    }
}